# -*- coding: utf-8 -*-
# @Time   : 2024/1/15 21:02
# @Author : Tom Bruce
array_my=[
    [1,2],
    [8,9],
    [8,7],
    [10,-1],
    [5,6],
    [3,4],
    [5,4]
]
def Associative_set(array):#array应该是列表，array的元素也应该是列表
    set_list,ass_set_list,set_list_invalid=[set(i) for i in array if -1 not in i],[],[set(i)-{-1} for i in array if -1 in i]
    for set1 in set_list:
        exit=0
        for s in ass_set_list:
            if set1.issubset(s):
                exit=1
                break
        if exit:
            continue
        while True:
            set1_old=set1
            for set2 in set_list:
                if set1&set2!=set():
                    set1= set1 | set2
            if set1==set1_old:
                break
        ass_set_list.append(set1)
    return ass_set_list,set_list_invalid

print('关联集合:',*Associative_set(array_my)[0],sep='\n')
print('无效ID的集合:',Associative_set(array_my)[1])